package com.adapters;

import java.util.ArrayList;
import com.witejavi.eneagrama.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MiAdapterListaEnlaces extends ArrayAdapter<String>{

	private ArrayList<String> lista;
	private ArrayList<String> listaSub;
	private ArrayList<Integer> imageResource;
	private Context context;
    	
    public MiAdapterListaEnlaces(Activity activity, Context context, ArrayList<String> listaTitulos, ArrayList<String> listaSubtitulos, ArrayList<Integer> listaImagenes) {
    	super(context, R.layout.hijo_enlaces_de_interes, listaTitulos);
    	
		this.context = context;		
		this.lista = listaTitulos;
		this.listaSub = listaSubtitulos;
		this.imageResource = listaImagenes;
        
	}   

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {		
		
		View view = null;
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            
            view = inflater.inflate(R.layout.hijo_enlaces_de_interes, null);
            TextView titulo = (TextView) view.findViewById(R.id.TextViewTitulo);
            TextView subtitulo = (TextView) view.findViewById(R.id.TextViewSubtitulo);
            ImageView icono = (ImageView) view.findViewById(R.id.imageViewEnlaces);
            
            titulo.setText(lista.get(position));
            subtitulo.setText(listaSub.get(position));
            icono.setImageResource(imageResource.get(position));
        } else {
            view = convertView;
        }
 		
        return view;
	}
	
	@Override
	public int getViewTypeCount() {  
		if (getCount() < 1)
			return 1;
	    return getCount();
	}

	@Override
	public int getItemViewType(int position) {
	    return position;
	}
	
	@Override
	public int getCount() {

		return lista.size();
	}

	@Override
	public long getItemId(int pos) {
		return pos;
	}
	
	
}
